package com.tianqu.tms.www.proxymember.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsDaoException;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.Codes;
import com.tianqu.tms.entity.Vendor;
import com.tianqu.tms.www.proxymember.actionform.ProxymemberCreationInputActionForm;
import com.tianqu.tms.www.proxymember.viewhelper.ProxyMemberCarSearchInputViewHelper;

/**
 * @author zhangxueliang
 * 待办登记 - 信息录入 中间跳转action
 */
public class ProxyMemberCarCreationDispatchAction extends TmsAction{
	private Logger logger = Logger.getLogger(ProxyMemberCarCreationDispatchAction.class);
	
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		ProxyMemberCarSearchInputViewHelper viewhelper = new ProxyMemberCarSearchInputViewHelper();
		ProxymemberCreationInputActionForm proxyForm = (ProxymemberCreationInputActionForm)form;
		
		viewhelper = formToViewHelper(viewhelper,proxyForm);
		Codes code = Codes.getInstance();
		viewhelper.setCarTypeList(code
				.getCodeslistByItemId(Codes.VEHICLE_TYPE));// 车辆类型
		viewhelper.setColorList(code
				.getCodeslistByItemId(Codes.VEHICLE_COLOR));// 车辆颜色
		viewhelper.setCarUseList(code
				.getCodeslistByItemId(Codes.USER_NATURE));// 使用性质list
		viewhelper.setCardTypeList(code
				.getCodeslistByItemId(Codes.PLATE_TYPE));// 号牌种类list
		viewhelper.setFuelTypeList(code
				.getCodeslistByItemId(Codes.FUEL_TYPE));// 燃料种类list
		viewhelper.setCountryStyleList(code
				.getCodeslistByItemId(Codes.VEHICLE_COUNTRY));// 国别list
		viewhelper.setAttributeList(code
				.getCodeslistByItemId(Codes.ATTACHMENT_PROPERTY));// 车辆状态list'
		viewhelper.setOwnerTypeList(code
				.getCodeslistByItemId(Codes.CAR_OWNER));// 车主类型list
		viewhelper.setGearBoxList(code.getCodeslistByItemId(Codes.GEARBOX_TYPE));//变速箱类型list
		
		
		// 车辆品牌
		Vendor vendor = Vendor.getInstance();
		viewhelper
				.setVendorList(vendor.findAllVendorInfo());
		if(!"".equals(uc.getAttribute("vin")) && uc.getAttribute("vin") != null){
			String vin = (String)uc.getAttribute("vin");
			viewhelper.setVin(vin);
		}
		
		uc.setAttribute(TmsConstants.VIEWHELP, viewhelper);
		
		
		logger.debug(this.getClass().getName() + "#execute was completed.");
		
		return mapping.findForward(TmsConstants.SUCCESS);
		
		
	}

	/**
	 * form ->viewHelper
	 * @param viewHelper
	 * @param proxyForm
	 * @return
	 * @throws TmsDaoException 
	 */
	private ProxyMemberCarSearchInputViewHelper formToViewHelper(ProxyMemberCarSearchInputViewHelper viewHelper,
			ProxymemberCreationInputActionForm proxyForm) throws TmsDaoException{
		viewHelper.setLicensePlate(proxyForm.getLicensePlate());
		viewHelper.setVendorCode(proxyForm.getVendorCode());
		viewHelper.setModelCode(proxyForm.getModelCode());
		viewHelper.setEngine(proxyForm.getEngine());
		viewHelper.setLoadquality(proxyForm.getLoadquality());
		viewHelper.setPassenger(proxyForm.getPassenger());
		viewHelper.setMileage(proxyForm.getMileage());
		viewHelper.setYearCarefulPeriod(proxyForm.getYearCarefulPeriod());
		viewHelper.setJqx(proxyForm.getJqx());
		viewHelper.setRegisterCardNo(proxyForm.getRegisterCardNo());
		viewHelper.setRegDate(proxyForm.getRegDate());
		viewHelper.setSendCardDate(proxyForm.getSendCardDate());
		viewHelper.setCarOwner(proxyForm.getCarOwner());
		viewHelper.setCarOwnerIdCardNo(proxyForm.getCarOwnerIdCardNo());
		viewHelper.setOwnerOrgNo(proxyForm.getOwnerOrgNo());
		viewHelper.setOwnerAddress(proxyForm.getOwnerAddress());
		viewHelper.setOwnerPhone(proxyForm.getOwnerPhone());
		viewHelper.setAgentName(proxyForm.getAgentName());
		viewHelper.setAgentAddress(proxyForm.getAgentAddress());
		viewHelper.setAgentOwnerIdCardNo(proxyForm.getAgentOwnerIdCardNo());
		viewHelper.setAgentPhone(proxyForm.getAgentPhone());
		viewHelper.setPrice(proxyForm.getPrice());
		viewHelper.setVendorId(proxyForm.getVendorId());
		viewHelper.setBrandId(proxyForm.getBrandId());
		viewHelper.setCarStyleId(proxyForm.getCarStyleId());
		//
		viewHelper.setDisplacement(String.valueOf(proxyForm.getDisplacement()));
		
		viewHelper.setCardType(String.valueOf(proxyForm.getCardType()));
		
		viewHelper.setCarType(String.valueOf(proxyForm.getCarType()));
		viewHelper.setCarUse(String.valueOf(proxyForm.getCarUse()));
		viewHelper.setColor(String.valueOf(proxyForm.getColor()));
		viewHelper.setCountryStyle(String.valueOf(proxyForm.getCountryStyle()));
		viewHelper.setGearbox(String.valueOf(proxyForm.getGearbox()));
		viewHelper.setFuelType(String.valueOf(proxyForm.getFuelType()));
		viewHelper.setOwnerType(String.valueOf(proxyForm.getOwnerType()));
		
		return viewHelper;
	}
}
